<template>
	<view>
		<view class="content">
			<view class="school" >
				公司名称
			</view>
			<input type="text" value="" v-model="form.company_name" placeholder="请输入公司名称"  />
		</view>
		<view class="content">
			<view class="school" >
				公司介绍
			</view>
			<input type="text" value="" v-model="form.introduce" placeholder="请填写公司介绍"  />
		</view>
		<view class="content" @click="logo">
			<view class="school" >
				公司logo
			</view>
			<input v-if="a==true" type="text" value="" disabled="true" placeholder="请上传公司logo"  />
			<image v-else style="width: 80rpx;height: 80rpx;border-radius: 50%;" :src="form.logo" mode=""></image>
		</view>
		<view class="content" @click="zp">
			<view class="school" >
				公司照片
			</view>
			<input v-if="b==true" type="text" value="" disabled="true" placeholder="请上传公司照片"  />
			<image v-else style="width: 80rpx;height: 80rpx;border-radius: 50%;" :src="form.company_pic" mode=""></image>
		</view>
		<view class="content" @click="qyzz">
			<view class="school" >
				企业资质
			</view>
			<input v-if="c==true" type="text" value="" disabled="true" v-model="form.enterprise_certification_pic" placeholder="请上传企业资质"  />
			<image v-else style="width: 80rpx;height: 80rpx;border-radius: 50%;" :src="form.enterprise_certification_pic" mode=""></image>
		</view>
		<view class="content">
			<view class="school" >
				从事行业
			</view>
			<input type="text" value="" v-model="form.industry" placeholder="请输入从事行业"  />
		</view>
		<view class="content" @click="show=true">
			<view class="school" >
				企业性质
			</view>
			<input type="text" disabled="true" value="" v-model="enterprise_type" placeholder="请选择企业性质"  />
		</view>
		<view class="content" @click="showw=true">
			<view class="school" >
				企业规模
			</view>
			<input type="text" value="" v-model="scale_type" placeholder="请选择企业规模"  />
		</view>
		<view class="content">
			<view class="school">所在地区</view>
			<!-- <picker :range="array" :range-key="'cname'" :value="p_value" @change="change1"  @columnchange="columnChange" mode="multiSelector">
				{{form.city_name}}-{{form.province_name}}
				
			</picker> -->
			<area2 :p_id="form.province_id" :c_id="form.area_id" @back_func_op="b1"></area2>
		</view>
		<view class="content">
			<view class="school" >
				详细地址
			</view>
			<input type="text" value="" v-model="form.address" placeholder="请填写公司详细地址"  />
		</view>
		<view class="content">
			<view class="school" >
				联系人
			</view>
			<input type="text" value="" v-model="form.link_name" placeholder="请填写联系人"  />
		</view>
		<view class="content">
			<view class="school" >
				工作职务
			</view>
			<input type="text" value="" v-model="form.link_position" placeholder="请填写联系人职务"  />
		</view>
		<view class="content">
			<view class="school" >
				联系电话
			</view>
			<input type="text" value="" v-model="form.link_mobile" placeholder="请填写电话"  />
		</view>
		<view class="content">
			<view class="school" >
				企业邮箱
			</view>
			<input type="text" value="" v-model="form.company_email" placeholder="请填写邮箱地址"  />
		</view>
		<view class="btn">
			<view class="dl" @click="baocun">
				<view class="dll">
					保存
				</view>
			</view>
		</view>
		<image-picker :hide="true" ref="imgPicker" :count="1" @success="upSuccess"></image-picker>
		<imgg :hide="true" ref="imgg" :count="1" @success="upSuccesss"></imgg>
		<zizhi :hide="true" ref="zizhi" :count="1" @success="upSuccessss"></zizhi>
		<u-select mode="single-column" v-model="show" :list="list" @confirm="confirm"></u-select>
		<u-select mode="single-column" v-model="showw" :list="listt" @confirm="confirmm"></u-select>
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex';
	import ImagePicker from '@/components/image-picker.vue';
	import imgg from '@/components/image-picker.vue';
	import zizhi from '@/components/image-picker.vue';
	import area2 from '@/pages/my/enterprise/area_two.vue'
	export default {
		components: {
			ImagePicker,
			imgg,
			zizhi,
			area2,
			//pickerAddress
		},
		data() {
			return {
				a:true,
				b:true,
				c:true,
				form:{},
				list: [],
				listt:[],
				show:false,
				showw:false,
				scale_type:'',
				enterprise_type:'',
				txt: '请选择所在地区',
				array:[[{'id':0,'cname':'请选择'}],[{'id':0,'cname':'请选择'}]],
				p_value:[0,0],
				c_id:'',
				p_id:'',
			}
		},
		created() {
			/*
			this.chakan()
			let self=this;
			uni.getStorage({
			    key: 'stateData',
			    success: function (res) {
			        self.stateData=res.data
					self.jt()
			    }
			});
			*/
		  
		},
		async onLoad() {
			await this.chakan()
			// this.form.province_id=2;
			console.log("第2步")
			let self=this;
			uni.getStorage({
			    key: 'stateData',
			    success: function (res) {
			        self.stateData=res.data
					self.jt()
			    }
			});
			//this.getCity()
			//this.form.province_id=2
			/*
			this.chakan()
			let self=this;
			uni.getStorage({
			    key: 'stateData',
			    success: function (res) {
			        self.stateData=res.data
					self.jt()
			    }
			});
			*/
			
			//this.getAddress();
			
		},
		methods: {
			change1(e){
				console.log("change1:")
				console.log(e)
			},
			async getAddress(e) {
				const res = await this.get('/index/Index/get_province')
				
					// console.log(item)
					//this.array[0] = res.data
					var that=this
					res.data.forEach(function(item,i){
						that.array[0].push(item)
					})
					
				
				
			},
			async getCity(e) {
				
				const res = await this.get('/index/Index/get_city_by_p_id',{p_id:this.id})
				console.log(res)
				
				this.array[1]=res.data
				
			},
			
			columnChange(e) {
				console.log("e:")
				console.log(e);
				if(e.detail.column==0){
					var n=e.detail.value;
					this.p_value[0]=n
					var p_id=this.array[0][n].id;
					this.p_id=p_id
					this.get_city_by_p_id(p_id);
					this.p_value[1]=0
					this.c_id=''
					this.form.province_name=this.array[0][n].cname
					
				}else if(e.detail.column==1){
					var nn=e.detail.value;
					this.p_value[1]=nn
					var c_id=this.array[1][nn].id
					this.c_id=c_id
					this.form.city_name=this.array[1][nn].cname
				}
				console.log(this.p_value)
				console.log("c_id:")
				console.log(this.c_id);
			},
			get_city_by_p_id(p_id){
			var that=this	
				this.get("/index/Index/get_city_by_p_id",{"p_id":p_id}).then(function(res){
					console.log("res")
					console.log(res)
					  //删除除了0以外的数据
					that.array[1].splice(1,that.array[1].length);
					res.data.forEach(function(item,i){
						//that.$set(that.array[1],i,item)
						that.array[1].push(item)
					})
					
					
					
					
				})
				
				
			},
			 async chakan() {
				// var _this=this
				let res =await this.post('/Index/UserCompany/get_user_company')
				console.log("promoise:")
				console.log(res)
					this.form=res.data
					//_this.form.province_id=2;
					this.a=false
					this.b=false
					this.c=false
					this.enterprise_type=this.form.enterprise_type_name
					this.scale_type=this.form.scale_type_type_name
					console.log(this.form);
					console.log("第一步")
				
				
			},
			jt(){
				for(let i in this.stateData.enterprise_type){
					this.list.push({value:i,label:this.stateData.enterprise_type[i]})
				}
				for(let i in this.stateData.scale_type){
					this.listt.push({value:i,label:this.stateData.scale_type[i]})
				}
			},
			async baocun(data) {
				//this.form.area_id=1;
				//this.form.area_id=this.c_id;
				//this.form.province_id=this.p_id;
				const res = await this.post('/Index/UserCompany/save_user_company', this.form);
				console.log(res)
				if(res.code==200){
					uni.showToast({
						title:'添加成功',
						duration:1000,
						icon:'none',
						success() {
							uni.navigateBack({
								
							})
						}
					})
				}
				console.log(res)
			},
			confirm(e){
				console.log(e)
				this.form.enterprise_type=e[0].value;
				this.enterprise_type=e[0].label;
			},
			confirmm(e){
				console.log(e)
				this.form.scale_type=e[0].value;
				this.scale_type=e[0].label;
			},
			logo(){
				this.$refs.imgPicker.ChooseImage()
			},
			zp(){
				this.$refs.imgg.ChooseImage()
			},
			qyzz(){
				this.$refs.zizhi.ChooseImage()
			},
			upSuccess(res) {
				console.log(res.file)
				// 选择完成图片回调返回 res.file 就是上传成功后端返回来的图片路径
				this.form.logo = res.file;
				this.a=false
			},
			upSuccesss(res) {
				console.log(res.file)
				// 选择完成图片回调返回 res.file 就是上传成功后端返回来的图片路径
				this.form.company_pic = res.file;
					this.b=false
			},
			upSuccessss(res) {
				console.log(res.file)
				// 选择完成图片回调返回 res.file 就是上传成功后端返回来的图片路径
				this.form.enterprise_certification_pic = res.file;
					this.c=false
			},
			b1(e){
				console.log("b1:")
				console.log(e)
				this.form.area_id=e.c_id
				this.form.province_id=e.p_id
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn{
		width: 100%;
		// display: flex;
		align-items: center;
		justify-content: space-around;
}
	.dl {
		width: 100%;
		padding: 30rpx;
		
		// transform: translateX(-50%);
	
		.dll {
			width: 100%;
			height: 90rpx;
			color: #FFFFFF;
			line-height: 90rpx;
			text-align: center;
			border-radius: 15rpx;
			background-color: #3291F8;
			border: 1rpx solid #3291F8;
		}
		.dlll{
			width: 100%;
			height: 90rpx;
			color: #ff0000;
			line-height: 90rpx;
			text-align: center;
			border-radius: 15rpx;
			background-color: #FFFFFF;
			border: 1rpx solid #ff0000;
		}
	}
	.content {
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #EEEEEE;
		font-size: 30rpx;
		.school{
			width: 250rpx;
		}
		input{
			width: calc(100% - 250rpx);
			font-size: 30rpx;
			text-align: right;
		}
	}
</style>
